package com.yungu.swift.api.route.v1.passenger;


import com.alibaba.dubbo.config.annotation.Reference;
import com.yungu.swift.api.base.BaseApi;
import com.yungu.swift.api.facade.PassengerFacade;
import com.yungu.swift.base.ResponseData;
import com.yungu.swift.constants.CommonConstant;
import com.yungu.swift.order.model.param.ApiValuationParam;
import com.yungu.swift.order.service.OrderFareService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 描述： 快车订单API
 *
 * @author Zerrion
 * @date 2018/4/11
 */
@Controller
@RequestMapping(value = "/api/v1/passenger")
@Api(value = "【乘客】【订单】【快车】接口", tags = "乘客订单快车相关操作")
public class ExpressOrderApi extends BaseApi {

    @Autowired
    private PassengerFacade passengerFacade;
    @Reference
    private OrderFareService orderFareService;


    @RequestMapping(value = {"/express/order/valuation"}, method = {RequestMethod.POST, RequestMethod.GET})
    @ResponseBody
    @ApiOperation(value = "快车估价接口", notes = "valuation", response = ResponseData.class)
    public ResponseData<Map<String, Object>> valuation(
            @ApiParam(name = "token", value = "token") @RequestParam(required = false) String token,
            @ApiParam(name = "appid", value = "APP标识", required = true) @RequestParam String appid,
            @ApiParam(name = "planTrip", value = "预估里程(公里)", required = true) @RequestParam Double planTrip,
            @ApiParam(name = "planTime", value = "预估时长(分钟)", required = true) @RequestParam Integer planTime,
            @ApiParam(name = "departTime", value = "出发时间") @RequestParam(required = false) Long departTime,
            @ApiParam(name = "adCode", value = "城市编码", required = true) @RequestParam String adCode,
            @ApiParam(name = "uuid", value = "登录用户uuid") @RequestParam(required = false) String uuid,
            HttpServletRequest request) {
        ApiValuationParam valuationParam = new ApiValuationParam();
        valuationParam.setAppid(appid);
//        valuationParam.setUserUuid(getUserUid(request));
        valuationParam.setUserUuid(uuid);
        valuationParam.setPlanTime(planTime);
        valuationParam.setPlanTrip(planTrip);
        valuationParam.setDepartTime(new Date(departTime));
        valuationParam.setAdCode(adCode);
        valuationParam.setBusinessType(CommonConstant.BUSINESS_TYPE_EXPRESS);
        valuationParam.setTypeTrip(1);
        return orderFareService.commonValuation(valuationParam);
    }


    @RequestMapping(value = {"/express/order/listTypeTime"}, method = {RequestMethod.POST, RequestMethod.GET})
    @ResponseBody
    @ApiOperation(value = "获取日租半日租条件数据源接口", notes = "获取日租半日租条件数据源接口", response = ResponseData.class)
    public ResponseData<List<Map<String, Object>>> getList(
            @ApiParam(name = "adCode", value = "区域编码", required = true) @RequestParam String adCode,
            @ApiParam(name = "appid", value = "APP标识", required = true) @RequestParam String appid) {

        return passengerFacade.listTypeTime(adCode, null, appid, CommonConstant.BUSINESS_TYPE_EXPRESS);
    }

    @RequestMapping(value = {"/express/order/valuateRental"}, method = {RequestMethod.POST, RequestMethod.GET})
    @ResponseBody
    @ApiOperation(value = "日租半日租估价接口", notes = "日租半日租估价接口", response = ResponseData.class)
    public ResponseData<Map<String, Object>> valuation(
            @ApiParam(name = "token", value = "token") @RequestParam(required = false) String token,
            @ApiParam(name = "appid", value = "APP标识", required = true) @RequestParam String appid,
            @ApiParam(name = "fareRuleUuid", value = "计价规则UUID", required = true) @RequestParam String fareRuleUuid) {

        return passengerFacade.valuateRent(token, appid, fareRuleUuid);
    }


}
